@use 'sass:map';

@use './shared' as *;
@use './design' as *;

$notice: () !default;
$notice: map.merge(
  (
    color: inherit,
    bg-color: get-css-var('bg-color-base'),
    b-color: get-css-var('border-color-light-2'),
    radius: get-css-var('radius-base'),
    s-color: get-css-var('shadow-color-base'),
    shadow: get-css-var('shadow-shape') get-css-var('notice-s-color'),
    v-padding: 8px,
    h-padding: 10px,
    mask-bg-color: transparent,
    title-font-size: get-css-var('font-size-primary'),
    title-color: get-css-var('content-color-primary'),
    icon-color: get-css-var('notice-color'),
    close-color: get-css-var('content-color-placeholder'),
    close-color-hover: get-css-var('content-color-base'),
    marker-bg-color: get-css-var('fill-color-secondary')
  ),
  $notice
);

.#{$namespace}-notice {
  &-vars {
    @include define-preset-values('notice', $notice);
  }

  @mixin define-notice-style($style-map) {
    @include define-preset-style('notice', $style-map);
  }

  @include basis;

  display: flex;
  flex-direction: column;
  align-items: center;

  $title: #{&}__title;
  $icon: #{&}__icon;
  $close: #{&}__close;

  &__wrapper {
    display: flex;
    flex-direction: column;
    width: 100%;
  }

  &__title {
    position: relative;
    margin-bottom: 3px;
    font-size: get-css-var('notice-title-font-size');
    color: get-css-var('notice-title-color');
  }

  &__content {
    position: relative;
    color: get-css-var('notice-color');
  }

  &__icon {
    display: flex;
    align-items: flex-start;
    padding-top: 4px;
    margin-inline-end: 10px;
    color: get-css-var('notice-icon-color');
  }

  &__close {
    display: flex;
    align-items: flex-start;
    align-self: flex-start;
    padding: 0 0 3px;
    margin-inline-start: 8px;
    color: get-css-var('notice-close-color');
    cursor: pointer;
    background-color: transparent;
    border: 0;
    outline: 0;
    transition: get-css-var('transition-color');

    &:hover,
    &:focus {
      color: get-css-var('notice-close-color-hover');
    }
  }

  &__item {
    display: flex;
    width: 336px;
    padding: get-css-var('notice-v-padding') get-css-var('notice-h-padding');
    color: get-css-var('notice-color');
    background-color: get-css-var('notice-bg-color');
    border: get-css-var('border-shape') get-css-var('notice-b-color');
    border-radius: get-css-var('notice-radius');
    box-shadow: get-css-var('notice-shadow');

    &--title-only {
      flex-direction: row;

      #{$title} {
        margin: 0;
        font-size: get-css-var('font-size-base');
      }

      #{$icon} {
        align-items: center;
        padding-top: 0;
        margin-inline-end: 8px;
      }

      #{$close} {
        align-items: center;
        align-self: stretch;
      }
    }

    &--has-icon#{&}--title-only {
      padding: get-css-var('notice-v-padding') get-css-var('notice-h-padding');
    }

    &--content-only {
      min-height: 60px;
    }

    &::before {
      @include inner-fixed;

      pointer-events: none;
      background-color: get-css-var('notice-mask-bg-color');
      border-radius: get-css-var('notice-radius');
      opacity: 80%;
    }

    &::after {
      position: absolute;
      top: 0;
      bottom: 0;
      left: 0;
      width: 5px;
      background-color: get-css-var('notice-marker-bg-color');
      border-radius: get-css-var('notice-radius') 0 0 get-css-var('notice-radius');
    }

    &--background::before {
      content: '';
    }

    &--marker::after {
      content: '';
    }

    $types: info success warning error;

    @each $type in $types {
      $color: if($type == 'info', 'primary', $type);

      &--color-only#{&}--#{$type} {
        @include define-notice-style(
          (
            title-color: 'color' $color 'dark-1',
            color: 'color' $color 'base',
            close-color: 'color' $color 'opacity-5',
            close-color-hover: 'color' $color 'base'
          )
        );
      }

      &--background#{&}--#{$type} {
        @include define-notice-style(
          (
            b-color: 'color' $color 'opacity-5',
            mask-bg-color: 'color' $color 'opacity-9',
            shadow: unset,
            close-color: 'color' $color 'opacity-7',
            close-color-hover: 'color' $color 'opacity-2'
          )
        );
      }

      &--background#{&}--color#{&}--#{$type} {
        @include define-notice-style(
          (
            title-color: 'color' $color 'dark-2',
            color: 'color' $color 'dark-2',
            icon-color: 'color' $color 'dark-1',
            marker-bg-color: 'color' $color 'dark-1'
          )
        );
      }

      &--#{$type} {
        @include define-notice-style(
          (
            icon-color: 'color' $color 'base',
            marker-bg-color: 'color' $color 'base'
          )
        );
      }
    }
  }
}
